package com.netblizzard.nms.util.database;

import java.sql.DriverManager;
import java.sql.SQLException;

public class MysqlDBO extends CommonDBO {
	private String dataBaseName = "mysql";
	private String characterEncoding = "utf-8";

	public MysqlDBO() {
		dbType = 1;
	}

	/* (non-Javadoc)
	 * @see com.netbliz.nms.util.database.CommonDBO#connect()
	 */
	@Override
	public boolean connect() {
		String jdbcDriverClassName = "com.mysql.jdbc.Driver";
		String jdbcUrl = "jdbc:mysql://" + serverAddr + ":" + serverPort + "/" + this.dataBaseName + "?user=" + userName + "&password=" + password
				+ "&useUnicode=true&&characterEncoding=" + this.characterEncoding;

		boolean rtn = false;
		try {
			Class.forName(jdbcDriverClassName);
			setJdbcConn(DriverManager.getConnection(jdbcUrl));
			rtn = true;
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rtn;
	}

	public String getDataBaseName() {
		return dataBaseName;
	}

	public void setDataBaseName(String dataBaseName) {
		this.dataBaseName = dataBaseName;
	}

	public String getCharacterEncoding() {
		return characterEncoding;
	}

	public void setCharacterEncoding(String characterEncoding) {
		this.characterEncoding = characterEncoding;
	}

}
